package com.iword.simple.event.demo;

import com.iword.simple.event.EventDispatcher;
import com.iword.simple.event.EventX;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@RestController
public class DemoEventTriggerController {

    @Autowired
    private EventDispatcher eventDispatcher;

    @RequestMapping("/aa")
    public String testaa(@RequestParam(name = "message") String message) {
        ParamDto paramDto = ParamDto.builder().code("test").name(message).build();
        EventX.sendEvent("/test/aa", paramDto);
        return "发送完成: " + message;
    }

    @RequestMapping("/bb")
    public String testbb(@RequestParam(name = "message") String message) {
        ParamDto paramDto = ParamDto.builder().code("test").name(message).build();
        EventX.sendEvent("/test/bb", Arrays.asList(paramDto, paramDto));
        return "发送完成: " + message;
    }

    @RequestMapping("/cc")
    public String testcc(@RequestParam(name = "message") String message) {
        Map<String, Object> param = new HashMap<>();
        param.put("type", "Map");
        param.put("message", message);
        EventX.sendEvent("/test/cc", param);
        return "发送完成: " + message;
    }

}
